package org.example.business_logic.component;

import lombok.Data;
import org.example.physics_engine.body.Transform;
import org.example.physics_engine.geometry.Vector2d;
import org.example.physics_engine.geometry.shapes.Triangle;
@Data
public class Baffle extends Triangle {
    public enum Direction{
        LEFT,
        RIGHT
    }
    private Direction direction;
    private boolean isUp;
    private double angular;

    public Baffle(Vector2d[] vertices, Direction direction) {
        super(vertices, new Transform());
        this.direction = direction;
        init();
    }

    public Baffle(Vector2d[] vertices, Transform transform, Direction direction) {
        super(vertices, transform);
        this.direction = direction;
        init();
    }

    public Baffle(Direction direction) {
        this.direction = direction;
    }

    /**
     * 初始化信息
     */
    private void init() {
        this.isUp = false;
        this.angular = 0;
    }

    /**
     * 反序列化用
     */
    @Deprecated
    public Baffle() {

    }

    public void flip(double theta) {
        angular += theta;
        if (this.direction == Direction.LEFT) {
            Vector2d transformed = getTransform().getTransformed(vertices[0]);
            rotate(theta / 180 * Math.PI, transformed.x, transformed.y);
        } else {
            Vector2d transformed = getTransform().getTransformed(vertices[1]);
            rotate(-theta / 180 * Math.PI, transformed.x, transformed.y);
        }
    }

    public void rise() {
        this.isUp = true;
    }


    public void down() {
        this.isUp = false;
    }
}
